﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using OnlineMediaAnalyzer.Models;

namespace OnlineMediaAnalyzer.Controllers.Analyzer
{
    public class PartyKeywordsController : Controller
    {
        private OnlineMediaAnalyzerContext db = new OnlineMediaAnalyzerContext();

        // GET: PartyKeywords
        public ActionResult Index()
        {
            var partyKeywords = db.PartyKeywords.Include(p => p.Party);
            return View(partyKeywords.ToList());
        }

        // GET: PartyKeywords/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            PartyKeyword partyKeyword = db.PartyKeywords.Find(id);
            if (partyKeyword == null)
            {
                return HttpNotFound();
            }
            return View(partyKeyword);
        }

        // GET: PartyKeywords/Create
        public ActionResult Create()
        {
            ViewBag.PartyID = new SelectList(db.Parties, "ID", "Name");
            return View();
        }

        // POST: PartyKeywords/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ID,PartyID,Keyword")] PartyKeyword partyKeyword)
        {
            if (ModelState.IsValid)
            {
                db.PartyKeywords.Add(partyKeyword);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.PartyID = new SelectList(db.Parties, "ID", "Name", partyKeyword.PartyID);
            return View(partyKeyword);
        }

        // GET: PartyKeywords/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            PartyKeyword partyKeyword = db.PartyKeywords.Find(id);
            if (partyKeyword == null)
            {
                return HttpNotFound();
            }
            ViewBag.PartyID = new SelectList(db.Parties, "ID", "Name", partyKeyword.PartyID);
            return View(partyKeyword);
        }

        // POST: PartyKeywords/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "ID,PartyID,Keyword")] PartyKeyword partyKeyword)
        {
            if (ModelState.IsValid)
            {
                db.Entry(partyKeyword).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.PartyID = new SelectList(db.Parties, "ID", "Name", partyKeyword.PartyID);
            return View(partyKeyword);
        }

        // GET: PartyKeywords/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            PartyKeyword partyKeyword = db.PartyKeywords.Find(id);
            if (partyKeyword == null)
            {
                return HttpNotFound();
            }
            return View(partyKeyword);
        }

        // POST: PartyKeywords/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            PartyKeyword partyKeyword = db.PartyKeywords.Find(id);
            db.PartyKeywords.Remove(partyKeyword);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
